<?php

/*
 * Fresns Control Panel (Standalone)
 * Copyright (C) 2021-Present 刘鑫
 * Released under the MIT License.
 */

namespace App\Plugins\FcpApi\TweetMembers;

use App\Base\Models\BaseAdminModel;
use App\Plugins\FcpApi\TweetLanguages\TweetLanguagesService;

class FsModel extends BaseAdminModel
{
    protected $table = FsConfig::CFG_TABLE;

    // 前台表单字段映射
    public function formFieldsMap()
    {
        return FsConfig::FORM_FIELDS_MAP;
    }

    // 新增搜索条件
    public function getAddedSearchableFields()
    {
        return FsConfig::ADDED_SEARCHABLE_FIELDS;
    }

    // hook-添加之后
    public function hookStoreAfter($id)
    {
        $langJson = request()->input('lang_json');
        if ($langJson) {
            TweetLanguagesService::addLanguages($langJson, FsConfig::CFG_TABLE, 'name', $id);
        }
    }

    public function hookUpdateAfter($id)
    {
        $langJson = request()->input('lang_json');
        if ($langJson) {
            TweetLanguagesService::addLanguages($langJson, FsConfig::CFG_TABLE, 'name', $id);
        }
    }

    // 搜索排序字段
    public function initOrderByFields()
    {
        $orderByFields = [
            'id' => 'DESC',
            // 'updated_at'    => 'DESC',
        ];

        return $orderByFields;
    }
}
